function common() {
}
common.urlBase = "/rest/wxcs/public";

common.restClient = function(url,successFun,data,isAsync,contentType){
    $.ajax({
        type:'POST',
        url:url,
        beforeSend:function(jqXHR) {
            //var h = document.body.clientHeight;
            //$("<div class=\"datagrid-mask\"></div>").css({display:"block",width:"100%",height:h}).appendTo("body");
            //$("<div class=\"datagrid-mask-msg\"></div>").html("正在努力加载数据，请稍候。。。").appendTo("body").css({display:"block",
            //    left:($(document.body).outerWidth(true) - 190) / 2,
            //    top:(h - 45) / 2});
        },
        complete: function(){
            //$('.datagrid-mask-msg').remove();
            //$('.datagrid-mask').remove();
        },
        data:data,
        dataType:'json',
        success:successFun,
        async:isAsync,
        contentType:contentType
    });
};

var CONST_AREA_ = "area_";
common.setAreaCombo = function(combo, type) {
    var area = sessionStorage.getItem(CONST_AREA_ + type);
    if(area) {
        combo.html(area);
        combo.selectmenu('refresh', true);
    } else {
        common.restClient(common.urlBase + "/area/" + type, function (data) {
            data = eval("(" + data + ")");
            var html = "";
            html += '<option value="0" selected="selected">请选择</option>';
            $(data).each(function () {
                html += '<option value="' + this.id + '">' + this.text + '</option>'
            });
            combo.html(html);
            sessionStorage.setItem(CONST_AREA_ + type, html);
            combo.selectmenu('refresh', true);
        })
    }
};

var CONST_UTIL_ = "util_";
common.setUtilCombo = function(combo, area, type) {
    var util = sessionStorage.getItem(CONST_UTIL_ + area + "_" + type);
    if(util) {
        combo.html(util);
        combo.selectmenu('refresh', true);
    } else {
        common.restClient(common.urlBase + "/util/" + area + "/" + type, function (data) {
            //data = eval("(" + data + ")");
            var html = "";
            html += '<option value="0">请选择</option>';
            $(data).each(function () {
                html += '<option value="' + this.id + '">' + this.text + '</option>'
            });
            combo.html(html);
            sessionStorage.setItem(CONST_UTIL_ + area + "_" + type, html);
            combo.selectmenu('refresh', true);
        })
    }
};

common.userQuery = function(successFun, postData) {
    common.restClient(common.urlBase + "/userQuery", function(data){
        successFun(data);
    }, postData);
};

common.userCharge = function(successFun, postData) {
    common.restClient(common.urlBase + "/userCharge", function(data){
        successFun(data);
    }, postData);
};

common.userTransaction = function(successFun, postData) {
    common.restClient(common.urlBase + "/userTransaction", function(data){
        successFun(data);
    }, postData);
};

common.showMsg = function(msg) {
    $("#message").html(msg);
    $.mobile.changePage("#pageMessage", {
        transition : "pop",
        role: "dialog"
    });
};

common.noteDecode = function(str) {
    var url = "";
    var strs = str.split("<hi:$$>");
    for(var i=0; i<strs.length; i++) {
        var cons = strs[i].split("<hi:=>");
        if(cons && cons.length == 2) {
            if(i == 0) {
                url += cons[1];
            } else if(i == 1) {
                url += "?" + cons[0] + "=" + cons[1];
            } else {
                url += "&" + cons[0] + "=" + cons[1];
            }
        }
    }
    return url;
};

common.errorCode = {
    "000": "调用成功",
    "US_001": "用户已开通",
    "US_002": "用户已冻结",
    "US_003": "用户未开通",
    "US_004": "BOSS鉴权失败",
    "FB_001": "该地区无此业务",
    "CA_001": "缴费号不存在",
    "CA_002": "行业单位逻辑错误",
    "MP_001": "手机支付超时",
    "MP_002": "手机支付逻辑错误",
    "JF_001": "未找到订单号",
    "JF_002": "订单号已缴纳",
    "JF_003": "上账失败冲正成功",
    "JF_004": "上账失败冲正失败",
    "JF_005": "余额不足",
    "JF_006": "手机支付未开户",
    "DW_201": "欠电费六个月以上请到电业营业厅",
    "DW_205": "缴费金额不能小于应缴金额",
    "DW_207": "负控购电户请到电力柜面缴费",
    "DW_208": "当日已经对帐，不允许再缴费",
    "DW_209": "缴费金额小于应收金额，缴费失败",
    "DW_210": "每月只能预存一次，缴费失败",
    "991": "调用行业单位接口失败",
    "992": "调用支付接口失败",
    "993": "调用BOSS接口失败",
    "994": "调用ADC接口失败",
    "995": "调用行业网关接口失败",
    "999": "系统错误",
    "其他": "未知错误"
};

common.statusCode = {
    "00": "交易中",
    "01": "交易成功",
    "02": "支付失败",
    "03": "支付成功，上账失败，冲正成功",
    "04": "支付成功，上账失败，冲正失败"
};

common.payRsCode = {
    "1": "支付成功",
    "0": "支付失败"
};